﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 8/25/2009
 * Time: 9:50 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using Miming.Model;

namespace Miming.Gui
{
	/// <summary>
	/// Description of ToDoListForm.
	/// </summary>
	public partial class ToDoListForm : BaseForm
	{
		public ToDoListForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			listView1.Resize += delegate { columnHeader3.Width = listView1.Width - 22 - (columnHeader1.Width + columnHeader2.Width); };
			newToolStripMenuItem.Click += delegate { MainForm.Instance.AddChild(new ToDoForm()); };
		}
		
		[System.ComponentModel.EditorBrowsableAttribute()]
		protected override void OnActivated(EventArgs e)
		{
			base.OnActivated(e);
			Model = SessionFacade.FindAllToDos();
		}
		
		protected override void OnModelChanged(EventArgs e)
		{
			base.OnModelChanged(e);
			listView1.Items.Clear();
			foreach (ToDo t in Model as IList<ToDo>) {
				ListViewItem li = listView1.Items.Add(t.Done ? "Yes" : "No");
				li.SubItems.Add(t.RemindOn.ToShortDateString());
				li.SubItems.Add(t.Note);
			}
		}
		
		void ListView1DoubleClick(object sender, EventArgs e)
		{
			if (listView1.SelectedItems.Count > 0) {
				ToDo t = (Model as IList<ToDo>)[listView1.SelectedItems[0].Index];
				MainForm.Instance.AddChild(new ToDoForm(t), "Edit To Do");
			}
		}
	}
}
